package cn.stylefeng.guns.modular.statistic.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.statistic.model.params.DayIncomeParam;
import cn.stylefeng.guns.modular.statistic.model.params.DayStatisticParam;
import cn.stylefeng.guns.modular.statistic.model.params.MonthIncomeParam;
import cn.stylefeng.guns.modular.statistic.model.params.MonthStatisticParam;
import cn.stylefeng.guns.modular.statistic.service.DayIncomeService;
import cn.stylefeng.guns.modular.statistic.service.DayStatisticService;
import cn.stylefeng.guns.modular.statistic.service.MonthIncomeService;
import cn.stylefeng.guns.modular.statistic.service.MonthStatisticService;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * 控制器
 *
 * @author liuqiang
 * @Date 2020-02-21 11:32:38
 */
@RestController
@RequestMapping("/statistic")
public class StatisticController extends BaseController {

    @Autowired
    private DayStatisticService dayStatisticService;

    @Autowired
    private MonthStatisticService monthStatisticService;

    @Autowired
    private DayIncomeService dayIncomeService;

    @Autowired
    private MonthIncomeService monthIncomeService;

    /**
     * 按天统计用户数量
     *
     * @author liuqiang
     * @Date 2020-02-21
     */
    @RequestMapping("/dayList")
    public ResponseData dayList(DayStatisticParam dayStatisticParam) {
        if(dayStatisticParam.getStartTime() == null || dayStatisticParam.getEndTime() == null){
            throw new ServiceException(BizExceptionEnum.PARAM_MISSING.getCode(),"开始日期或结束日期不能为空");
        }

        if(dayStatisticParam.getEndTime() < dayStatisticParam.getStartTime()){
            throw new ServiceException(BizExceptionEnum.PARAM_WRONG.getCode(),"结束日期不能小于开始日期");
        }
        return ResponseData.success(dayStatisticService.statisticsDay(dayStatisticParam));
    }


    /**按月份统计用户数量
     * @param monthStatisticParam
     * @return
     */
    @RequestMapping("/monthList")
    public ResponseData monthList(MonthStatisticParam monthStatisticParam) {
        if(monthStatisticParam.getStartTime() == null || monthStatisticParam.getEndTime() == null){
            throw new ServiceException(BizExceptionEnum.PARAM_MISSING.getCode(),"开始月份或结束月份不能为空");
        }

        if(monthStatisticParam.getEndTime() < monthStatisticParam.getStartTime()){
            throw new ServiceException(BizExceptionEnum.PARAM_WRONG.getCode(),"结束月份不能小于开始月份");
        }
        return ResponseData.success(monthStatisticService.statisticsMonth(monthStatisticParam));
    }

    /**
     * 按天统计收入
     *
     * @author liuqiang
     * @Date 2020-02-22
     */
    @RequestMapping("/income/dayList")
    public ResponseData incomeDayList(DayIncomeParam dayIncomeParam) {

        if(dayIncomeParam.getStartTime() == null || dayIncomeParam.getEndTime() == null){
            throw new ServiceException(BizExceptionEnum.PARAM_MISSING.getCode(),"开始日期或结束日期不能为空");
        }

        if(dayIncomeParam.getEndTime() < dayIncomeParam.getStartTime()){
            throw new ServiceException(BizExceptionEnum.PARAM_WRONG.getCode(),"结束日期不能小于开始日期");
        }
        return ResponseData.success(this.dayIncomeService.statisticDay(dayIncomeParam));
    }


    /**
     * 按月份统计收入
     *
     * @author liuqiang
     * @Date 2020-02-22
     */
    @RequestMapping("/income/monthList")
    public ResponseData list(MonthIncomeParam monthIncomeParam) {
        if(monthIncomeParam.getStartTime() == null || monthIncomeParam.getEndTime() == null){
            throw new ServiceException(BizExceptionEnum.PARAM_MISSING.getCode(),"开始月份或结束月份不能为空");
        }

        if(monthIncomeParam.getEndTime() < monthIncomeParam.getStartTime()){
            throw new ServiceException(BizExceptionEnum.PARAM_WRONG.getCode(),"结束月份不能小于开始月份");
        }

        return ResponseData.success(this.monthIncomeService.statisticMonth(monthIncomeParam));
    }
}


